package scantask.containers;

import java.awt.Color;
import java.util.Vector;

import scantask.containers.exceptions.IllegalAreaException;
import scantask.containers.exceptions.UnInitializeObjectException;

public class Area {
	
	private final static Color DEFAULT_COLOR = Color.blue;
	
	private Coordinate _center;
	private Vector<Coordinate> _vertexes;
	private String _name;
	private String _type;
	private String _color;
	
	public Area(Coordinate center, Vector<Coordinate> vertexes, String name, String type, String color) throws IllegalAreaException {
		if (center == null) {
			scantask.server.utilities.logging.SingletonLogger.getLogger().warning("Illegal center coordinate is null, failed create new area");
			throw new IllegalAreaException();
		}
		if ((name == null) || (name.compareTo("") == 0)) {
			scantask.server.utilities.logging.SingletonLogger.getLogger().warning("Illegal area name, failed create new area");
			throw new IllegalAreaException();
		}
		if ((type == null) || (type.compareTo("") == 0)) {
			scantask.server.utilities.logging.SingletonLogger.getLogger().warning("Illegal area type, failed create new area");
			throw new IllegalAreaException();
		}
		this._center = center;
		this._vertexes = vertexes;
		this._name = name;
		this._type = type;
		this._color = color;
	}
	
	public Area(Coordinate center, String name, String type) throws IllegalAreaException {
		if (this._center == null) {
			scantask.server.utilities.logging.SingletonLogger.getLogger().warning("Illegal center coordinate is null, failed create new area");
			throw new IllegalAreaException();
		}
		if ((this._name == null) || (this._name.compareTo("") == 0)) {
			scantask.server.utilities.logging.SingletonLogger.getLogger().warning("Illegal area name, failed create new area");
			throw new IllegalAreaException();
		}
		if ((this._type == null) || (this._type.compareTo("") == 0)) {
			scantask.server.utilities.logging.SingletonLogger.getLogger().warning("Illegal area type, failed create new area");
			throw new IllegalAreaException();
		}
		this._center = center;
		this._name = name;
		this._type = type;
		this._vertexes = null;
		this._color = null;
	}
	
	public Coordinate getCenterCoordinate() {
		return this._center;
	}
	
	public Vector<Coordinate> getVertixes() throws UnInitializeObjectException {
		if (this._vertexes == null) {
			throw new UnInitializeObjectException();
		}
		return this._vertexes;
	}
	
	public String getName() {
		return this._name;
	}
	
	public String getType() {
		return this._type;
	}
	
	public Color getColor() {
		Color c = scantask.containers.ColorMap.getColor(this.getColorStr());
		if (c == null) {
			return DEFAULT_COLOR;
		}
		return c;
	}
	
	public String getColorStr() {
		return this._color;
	}
	
	public void clearVertexes() {
		this._vertexes.clear();
	}

}
